import { Menu as IMenu } from './types'

export const useMenus = () => {
    const getParents = (id: number, menus: IMenu[]): string[] => {
        const item = menus.find((i) => i.id == id)
        if (item == undefined || item.parent_id == 0) {
            return []
        }

        let result = [`${item.parent_id}`]
        let pid = getParents(item.parent_id, menus)

        pid.map((p) => `${p}`)
        result.push(...pid)
        return result
    }

    return {
        getParents
    }
}